package com.example.clientsideapplication;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;

public class ViewMerchantOfferInfo extends Activity {
	private TextView productNameTW, productPriceTW, productInfoTW, dataStartTW, dataEndTW;
	private int startDay, startMonth, startYear;
	private int endDay, endMonth, endYear;
	private Double price;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_offer_info);
		
		productNameTW = (TextView) findViewById(R.id.view_offer_info_product_name_value);
		productPriceTW = (TextView) findViewById(R.id.view_offer_info_product_price_value);
		productInfoTW = (TextView) findViewById(R.id.view_offer_info_product_info_value);
		dataStartTW = (TextView) findViewById(R.id.view_offer_info_product_start_date_value);
		dataEndTW = (TextView) findViewById(R.id.view_offer_info_product_end_date_value);

		Intent intent = getIntent();
		Offer offer = (Offer) intent.getSerializableExtra("offer");
		
		// Date inizia il conteggio degli anni da 1900 e quello dei mesi da 0, quindi devo sommare 1900 agli anni
		// e 1 ai mesi, per ottenere la data corretta.
		startDay = offer.getStartDate().getDate();
		startMonth = offer.getStartDate().getMonth() + 1;
		startYear = offer.getStartDate().getYear() + 1900;
		endDay = offer.getEndDate().getDate();
		endMonth = offer.getEndDate().getMonth() + 1;
		endYear = offer.getEndDate().getYear() + 1900;
		price = offer.getProductPrice();
		
		productNameTW.setText(offer.getProductName());
		productInfoTW.setText(offer.getProductInfo());
		productPriceTW.setText(price.toString() + " euro");
		dataStartTW.setText(new StringBuilder().append(startDay).append("-")
				.append(startMonth).append("-").append(startYear).append(" "));
		dataEndTW.setText(new StringBuilder().append(endDay).append("-")
				.append(endMonth).append("-").append(endYear).append(" "));
		
	}
}
